//
//  NSDate+YH.m
//  MoreCoin
//
//  Created by 林宁宁 on 2019/10/11.
//  Copyright © 2019 MoreCoin. All rights reserved.
//

#import "NSDate+YH.h"
#import <YYCategories/NSDate+YYAdd.h>

@implementation NSDate (YH)


/** 转时间字符串
 为空默认 yyyy-MM-dd HH:mm:ss 格式
 */
- (NSString *)yh_stringByFormate:(NSString *)formate{
    NSDateFormatter * dateFormater = [NSDateFormatter new];
    if(formate){
        dateFormater.dateFormat = formate;
    }else{
        dateFormater.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    }
    return [dateFormater stringFromDate:self];
}

+ (NSTimeInterval)yh_timestamp{
    return [[NSDate date] timeIntervalSince1970];
}




/// 转成时间戳 -> 月日格式显示
+ (NSString *)yh_timestampToDayFormat:(NSInteger)timestamp{
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:timestamp];
    return [date yh_stringByFormate:@"MM-dd HH:mm:ss"];
}

+ (NSString *)yh_nowTime{
    return [NSString stringWithFormat:@"%.0f",[[NSDate date] timeIntervalSince1970]*1000];
}



/** 这个日期是星期几*/
- (NSString *)yh_dateWeekday{
    NSInteger weekday = self.weekday;
    switch (weekday) {
        case 1: return @"日";
        case 2: return @"一";
        case 3: return @"二";
        case 4: return @"三";
        case 5: return @"四";
        case 6: return @"五";
        case 7: return @"六";
        default:
            return @"";
            break;
    }
}

- (NSString *)yh_identifyToDay{
    return [self yh_stringByFormate:@"yyyyMMdd"];
}
- (NSString *)yh_timesTemp{
    return @([self timeIntervalSince1970]).stringValue;
}

/// 时间戳
+ (NSInteger)yh_timeTemp{
    return [[NSDate date] timeIntervalSince1970];
}
/// 时间戳 毫秒
+ (NSInteger)yh_timeTempMillisecond{
    return [[NSDate date] timeIntervalSince1970]*1000;
}

@end
